package view;

import java.math.BigDecimal;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import net.miginfocom.swing.MigLayout;

public class OutputPanel extends JPanel{
	
	private JLabel population;
    private JLabel sample;
    private JLabel pMean;
    private JTextField pMeanField;

	private JLabel sMean;
    private JTextField sMeanField;
    private JLabel pVariance;
    private JTextField pVarianceField;
    private JLabel sVariance;
    private JTextField sVarianceField;
	
	public OutputPanel(){
		this.setLayout(new MigLayout());
		
		initComponent();
		addComponent();
	}

	private void initComponent() {
		
        // population
        population = new JLabel("Population:");
        pMean = new JLabel("Mean:");
        pMeanField = new JTextField(6);
        pMeanField.setEnabled(false);
        pVariance = new JLabel("Variance:");
        pVarianceField = new JTextField(6);
        pVarianceField.setEnabled(false);
        
        //sample
        sample = new JLabel("Sample:");
        sMean = new JLabel("Mean:");
        sMeanField = new JTextField(6);
        sMeanField.setEnabled(false);
        sVariance = new JLabel("Variance:");
        sVarianceField = new JTextField(6);	
        sVarianceField.setEnabled(false);
		
	}

	private void addComponent() {
		
		add(population);
    	add(sample, "gapleft 90, wrap");
        
    	add(pMean, "gapleft 60");
    	add(pMeanField);
    	add(sMean);
    	add(sMeanField, "wrap");
    	
    	add(pVariance, "gapleft 60");
    	add(pVarianceField);
    	add(sVariance);
    	add(sVarianceField, "wrap");
		
	}
	
    public void setpMeanField(Double pMeanField) {
		this.pMeanField.setText(new BigDecimal(String.valueOf(pMeanField)).setScale(4, BigDecimal.ROUND_HALF_UP).toString());
	}

	public void setsMeanField(Double sMeanField) {
		this.sMeanField.setText(new BigDecimal(String.valueOf(sMeanField)).setScale(4, BigDecimal.ROUND_HALF_UP).toString());
	}

	public void setpVarianceField(Double pVarianceField) {
		this.pVarianceField.setText(new BigDecimal(String.valueOf(pVarianceField)).setScale(4, BigDecimal.ROUND_HALF_UP).toString());
	}

	public void setsVarianceField(Double sVarianceField) {
		this.sVarianceField.setText(new BigDecimal(String.valueOf(sVarianceField)).setScale(4, BigDecimal.ROUND_HALF_UP).toString());
	}

}
